<?php echo $this->validation->error_string; ?>
<?php echo form_open($this->curl .'/create/'. $id_test, 'id="create_form"')?>
	
<table class="nostyle forma" width="100%" border="0" cellpadding="3" cellspacing="0">
<tr>
	<th style="width: 180px;"><?php $this->load->view('_elements/obligatory.php'); ?><?php echo $this->personality_traits_model->fields['trait']?></th>
	<td><div class="input_300"><?php echo form_input('trait', $this->validation->trait, 'class="input-text"')?></div></td>
</tr>
<tr>
	<th><?php echo $this->personality_traits_model->fields['description']?></th>
	<td><textarea name="description" id="description"><?php echo $this->validation->description ?></textarea></td>
</tr>
<tr>
	<td colspan="2">&nbsp;</td>
</tr>
<tr>
	<th style="vertical-align: top !important">
		<?php echo T_('Points Range'); ?><br /><br /><br />
		<input onclick="addNewRange()" name="new_range" type="button" class="" id="new_range" value="<?php echo T_('New Range')?>" />
	</th>
	<td>
		<table id="points" class="nostyle" width="200" border="0" cellpadding="3" cellspacing="0">
		<thead>
		<tr>
			<th></th>
			<th><?php echo T_('From'); ?></th>
			<th><?php echo T_('To'); ?></th>
			<th><?php echo T_('Description'); ?></th>
		</tr>
		</thead>
		<tbody>
		<?php foreach ($points as $i => $point): ?>
		<tr>
			<td><a href="javascript:void(0)" title="<?php echo T_('Delete'); ?>" class="btn_del_option" id="opt_"><img src="/img/close.png" width="16" height="16" /></a></td>
			<td><div class="input_80"><?php echo form_input('points_from[]', $point['from'], 'class="input-text"')?></div></td>
			<td><div class="input_80"><?php echo form_input('points_to[]', $point['to'], 'class="input-text"')?></div></td>
			<td><div class="textarea_80"><textarea cols="5" rows="2" name="points_description[]"><?php echo $point['description']; ?></textarea></div></td>
		</tr>
		<?php endforeach; ?>
		</tbody>
		</table>
	</td>
</tr>
<tr>
	<td colspan="2">&nbsp;</td>
</tr>
<tr>
	<td></td>
	<td>
		<input name="edit" type="submit" class="btn btn_save" id="submit" value="<?php echo T_('Submit')?>" />
		<input name="reset"  type="reset"  class="btn btn_clear" id="reset" value="<?php echo T_('Reset')?>" onclick="$('#create_form input[type=text]').val('');" />		
	</td>
</tr>
</table>

<?php echo form_close()?>

<script type="text/javascript">

function addNewRange()
{
	$("#points tbody").append('<tr>'+
			'<td><a href="javascript:void(0)" title="<?php echo T_('Delete'); ?>" class="btn_del_option" id="opt_"><img src="/img/close.png" width="16" height="16" /></a></td>'+
			'<td><div class="input_80"><input type="text" class="input-text" value="" name="points_from[]"></div></td>'+
			'<td><div class="input_80"><input type="text" class="input-text" value="" name="points_to[]"></div></td>'+
			'<td><div class="textarea_80"><textarea name="points_description[]" rows="2" cols="5"></textarea></div></td>'+
		'</tr>');

	$('.btn_del_option').unbind().click(function(){
		deleteRange($(this));
	})
}

function deleteRange(obj)
{
	if (!confirm('<?php echo T_('Are you sure you want to delete this Points Range?')?>')) return false;
	
	$(obj).parent().parent().remove();
}

$(document).ready(function(){
	$('.btn_del_option').unbind().click(function(){
		deleteRange($(this));
	})
});
</script>